<template>
  <el-dialog
    title="修改派送地址"
    :modal="false"
    :visible.sync="centerDialogVisible"
    width="50%"
    center
  >
    <div>
      <el-row :gutter="6">
        <el-form
          ref="paramForm"
          :model="paramData"
          size="mini"
          label-width="280px"
        >
          <el-row>
            <el-col :span="14">
              <el-form-item label="派送地址" prop="dispatchAddress">
                <el-input
                  v-model="paramData.dispatchAddress"
                  placeholder="请输入派送地址"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="14">
              <el-form-item label="派送地址2" prop="dispatchAddress2">
                <el-input
                  v-model="paramData.dispatchAddress2"
                  placeholder="请输入派送地址2"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="14">
              <el-form-item label="州/省" prop="dispatchProvince">
                <el-input
                  v-model="paramData.dispatchProvince"
                  placeholder="请输入州/省"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="14">
              <el-form-item label="城市" prop="dispatchCity">
                <el-input
                  v-model="paramData.dispatchCity"
                  placeholder="请输入城市"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="14">
              <el-form-item label="邮编" prop="dispatchZipCode">
                <el-input
                  v-model="paramData.dispatchZipCode"
                  placeholder="请输入邮编"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="14">
              <el-form-item label="公司名" prop="dispatcher">
                <el-input
                  v-model="paramData.dispatcher"
                  placeholder="请输入公司名"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="14">
              <el-form-item label="联系人" prop="dispatchLinkMan">
                <el-input
                  v-model="paramData.dispatchLinkMan"
                  placeholder="请输入联系人"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="14">
              <el-form-item label="联系电话" prop="dispatchPhone">
                <el-input
                  v-model="paramData.dispatchPhone"
                  placeholder="请输入联系电话"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="14">
              <el-form-item
                label="邮箱"
                prop="dispatchEmail"
                :rules="[
                  {
                    required: false,
                    message: '请输入邮箱地址',
                    trigger: 'blur'
                  },
                  {
                    type: 'email',
                    message: '请输入正确的邮箱地址',
                    trigger: ['blur', 'change']
                  }
                ]"
              >
                <el-input
                  v-model="paramData.dispatchEmail"
                  placeholder="请输入联系电话"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-row>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="centerDialogVisible = false">取 消</el-button>
      <el-button
        type="primary"
        @click="editDispatchAddress"
        v-loading.fullscreen.lock="fullscreenLoading"
        >确 定</el-button
      >
    </span>
  </el-dialog>
</template>

<script>
import { ajax } from "@/store/yg/common/utils";
import axios from "axios";
import * as constant from "@/store/yg/common/constant";
import { m } from "@/store/yg/common/local";
export default {
  props: ["row", "data", "more"],
  data() {
    return {
      fullscreenLoading: false,
      centerDialogVisible: false,
      paramData: {
        id: 0,
        dispatchAddress2: "",
        dispatchAddress: "",
        dispatchProvince: "",
        dispatchCity: "",
        dispatcher: "",
        dispatchLinkMan: "",
        dispatchPhone: "",
        dispatchZipCode: "",
        dispatchEmail: ""
      }
    };
  },

  methods: {
    //修改派送仓库地址
    editDispatchAddress() {
      var param = {};
      param["id"] = this.data["id"];
      param["fba"] = 0;
      param["dispatchAddress"] = this.paramData.dispatchAddress;
      param["dispatchAddress2"] = this.paramData.dispatchAddress2;
      param["dispatchProvince"] = this.paramData.dispatchProvince;
      param["dispatchCity"] = this.paramData.dispatchCity;
      param["dispatcher"] = this.paramData.dispatcher;
      param["dispatchLinkMan"] = this.paramData.dispatchLinkMan;
      param["dispatchPhone"] = this.paramData.dispatchPhone;
      param["dispatchZipCode"] = this.paramData.dispatchZipCode;
      param["dispatchEmail"] = this.paramData.dispatchEmail;
      console.log("param:", param);
      this.fullscreenLoading = true;
      ajax("editDispatchAddress", param).then(
        res => {
          this.fullscreenLoading = false;
          if (res.code != 200) {
            if (null != res.message) {
              this.$message.error(m(res.message));
            } else {
              this.$message.error("修改失败!");
            }
          } else {
            this.$message.success("修改成功!");
            this.centerDialogVisible = false;
          }
        },
        error => {
          console.log(error);
        }
      );
    }
  },
  mounted() {
    this.paramData.dispatchAddress2 = this.data["dispatchAddress2"];
    this.paramData.dispatchAddress = this.data["dispatchAddress"];
    this.paramData.dispatchProvince = this.data["dispatchProvince"];
    this.paramData.dispatchCity = this.data["dispatchCity"];
    this.paramData.dispatcher = this.data["dispatcher"];
    this.paramData.dispatchLinkMan = this.data["dispatchLinkMan"];
    this.paramData.dispatchPhone = this.data["dispatchPhone"];
    this.paramData.dispatchZipCode = this.data["dispatchZipCode"];
    this.paramData.dispatchEmail = this.data["dispatchEmail"];
  }
};
</script>

<style></style>
